package au.com.mason.propertyTracker.domain;

import java.math.BigDecimal;
import java.text.DecimalFormat;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Transient;

@Entity
@PrimaryKeyJoinColumn(name="propertyId")
public class RentalProperty extends Property {
	private boolean tenanted;
	private BigDecimal rent;
	private FurnishedType furnishedType;
	
	@Column
	public boolean isTenanted() {
		return tenanted;
	}
	
	@Transient
	public String isCurrentlyTenantedString() {
		return tenanted?"Yes":"No";
	}

	public void setTenanted(boolean currentlyTenanted) {
		this.tenanted = currentlyTenanted;
	}

	@Column
	public BigDecimal getRent() {
		return rent;
	}
	
	public void setRent(BigDecimal rent) {
		this.rent = rent;
	}

	@Transient
	public String getYieldString() {
		if (rent != null && priceFrom != null) {
			double value = ((rent.doubleValue()*52.00)/priceFrom.doubleValue())*100.00;
			
			DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance();
			format.applyPattern("###,###,###.##");
			return format.format(value);
		}
		
		return "";
	}

	@Enumerated(EnumType.STRING)
	public FurnishedType getFurnishedType() {
		return furnishedType;
	}

	public void setFurnishedType(FurnishedType furnishedType) {
		this.furnishedType = furnishedType;
	}

}
